1. Field of the Invention
The present invention relates generally to an improved data processing system, and in particular to a computer implemented method, data processing system, and computer program product for detecting circular buffer overrun.
2. Description of the Related Art
Circular buffers are a staple of computer science memory management to solve the problem of matching variations in the processing speed of asynchronous data producers and data consumers. A circular buffer is a data structure that uses a single, fixed size buffer as if it were connected end-to-end. In a circular buffer, information is written starting at a given location and continues to the end of the buffer, whereupon the next piece of information is written at the first location in the buffer. In like manner, information is read from the buffer in the order in which the information was entered. When the end of the buffer is reached, the next location to be processed is again the first location in the buffer.
In the current art, pointers are used to manage the locations in a circular buffer where a process will write to or read from. A mechanism known as a “head pointer” is used to point to the buffer location to which data is to be next written, and a mechanism known as a “tail pointer” is used to point to the buffer location from which data is to be next read. In a typical circular buffer protocol embodiment, a data producer uses the head pointer to determine the next buffer location to be written. After the data producer writes data to the buffer starting at the determined location, the data producer then updates the head pointer value to the location the data producer intends to next fill and reads the tail pointer value to ensure that the location that the data producer intends to next fill has indeed been emptied by the data consumer. In like manner, a data consumer uses the tail pointer to determine the next location to be read. After the data consumer reads data from the buffer starting at the determined location, the data consumer updates the tail pointer value to the location that the data consumer intends to next process, and then reads the head pointer value to ensure that the location that the data consumer intends to next process has indeed been filled by the data producer. An example of a data producer/data consumer pair is a data producer which may be a LAN receiver (such as an Ethernet adapter) receiving data packets from the Internet and placing the packets on a circular TCP/IP protocol processing program's receive circular buffer, while the data consumer may be the TCP/IP protocol processing program itself. In another example, the data producer may be a computer keyboard, and the data consumer may be the operating system's keyboard device driver program from the keyboard's circular buffer. In this example, the keyboard circular buffer in turn parses out the incoming key strokes to the applications owning the various display “windows”, thus itself becoming a data producer for those various data consuming applications.
A problem with the existing circular buffer protocol embodiment is that while in theory it may work well, in practice, in modern computer systems, this embodiment may result in long latency accesses. Often the data producer and data consumer partner processes are electrically at a significant distance from each other. The head pointer is stored physically at the location of the data producer, and the tail pointer is stored physically at the location of the data consumer. In this situation, the data producer must read the tail pointer stored at the location of the data consumer partner process, and the data consumer must read the head pointer stored at the location of the data producer partner process. These pointer reads produce long latency accesses due to the distance between the data producer and consumer.
Therefore, it would be advantageous to have a circular buffer protocol that prevents long latency accesses by avoiding the reading of a pointer of a partner process. It would also be advantageous to have a mechanism for determining when a partner process has violated the circular buffer protocol causing the circular buffer to overflow.